package com.ctz.commonframe.ui.widget;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ctz.commonframe.R;
import com.ctz.commonframe.utils.CommonUtil;
import com.ctz.commonframe.utils.DateUtil;

public class FileChooseAdapter extends AbsAdapter<Map<String, Object>> {

	public FileChooseAdapter(Context context, List<Map<String, Object>> datas) {
		super(context, datas, R.layout.item_file);
	}

	@Override
	public void convert(AdapterViewHolder holder, Map<String, Object> map) {
		ImageView ivSelectTag = holder.getView(R.id.selected_tag);
		TextView tvBack = holder.getView(R.id.tvBack);
		TextView tvDesc = holder.getView(R.id.tvDesc);
        ImageView image = holder.getView(R.id.image);
        TextView tvName = holder.getView(R.id.tvName);

		if ((Integer) map.get("type") == 1) {
			ivSelectTag.setVisibility(View.VISIBLE);
		} else {
			ivSelectTag.setVisibility(View.GONE);
		}

		if ((Integer) map.get("type") == 3) {
            tvBack.setVisibility(View.VISIBLE);
		} else {
            tvBack.setVisibility(View.GONE);
		}

		if ((Integer) map.get("type") == 2) {
            tvDesc.setVisibility(View.VISIBLE);
			String size = CommonUtil.convertFileSize(map.get("size") + "");

			String date = "";
			try {
				date = DateUtil.millis2String((Long) (map.get("date")), "yyyy-MM-dd HH:dd:ss");
			} catch (Exception e) {
				e.printStackTrace();
			}
			tvDesc.setText(size + "，" + date);
		} else {
            tvDesc.setVisibility(View.GONE);
		}
        image.setImageResource((Integer) map.get("pic"));
		tvName.setText((String) map.get("title"));
	}

}
